package com.cp.admin.modular.user.controller;

import com.cp.admin.modular.user.model.ProductPrice;
import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.user.service.IProductPriceService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2020-08-26 09:55:45
 */
@Controller
@RequestMapping("/productPrice")
public class ProductPriceController extends BaseController {

    private String PREFIX = "/user/productPrice/";

    @Autowired
    private IProductPriceService productPriceService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "productPrice.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/productPrice_add")
    public String productPriceAdd() {
        return PREFIX + "productPrice_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/productPrice_update/{productPriceId}")
    public String productPriceUpdate(@PathVariable Long productPriceId, Model model) {
        ProductPrice productPrice = productPriceService.selectById(productPriceId);
        model.addAttribute("item",productPrice);
        LogObjectHolder.me().set(productPrice);
        return PREFIX + "productPrice_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return productPriceService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ProductPrice productPrice) {
        productPriceService.insert(productPrice);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long productPriceId) {
        productPriceService.deleteById(productPriceId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ProductPrice productPrice) {
        productPriceService.updateById(productPrice);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{productPriceId}")
    @ResponseBody
    public Object detail(@PathVariable("productPriceId") Long productPriceId) {
        return productPriceService.selectById(productPriceId);
    }
}
